function formatDate (strTime) {
    if(strTime == null)
        return "";
    var date = new Date(strTime);
    return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
}
function formatTime (strTime) {
    if(strTime == null)
        return "";
    var date = new Date(strTime);
    return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
}
$(document).ready(function () {
    $(".inquire-messege").click(function () {
        var inquire_image={};
        var status="";
        var demand_number;
        var demand_person;
        var demand_phone;

        //获取元素值
        demand_number=$(".inquire-number").val();
        if(demand_number != null && demand_number != "")
            inquire_image.orderNo=demand_number;

        demand_person=$(".inquire-receiver").val();
        if(demand_person != null && demand_person != "")
            inquire_image.toName=demand_person;

        demand_phone=$(".inquire-tel").val();
        if(demand_phone != null && demand_phone != "")
            inquire_image.cellphone=demand_phone;

        $("input[name='inquire_chose']:checked").each(function () {
            status += this.value + ",";
        });
        if(status.length > 1){
            status = status.substring(0,status.length - 1);
            inquire_image.status=status;
        }

        //移除上次查询结果
        $(".add").remove();

        //获取数据
        $.getJSON("/JRD/order_queryMidSonOrder.json",inquire_image,function(data){
            if(data.success){
                for(var i=0;i<data.order.length;i++){
                    var msg;
                    if(data.order[i].middleMessage==null&&data.order[i].receiveMessage==null){
                        msg=""
                    }else{
                        msg=data.order[i].middleMessage==null?data.order[i].receiveMessage:data.order[i].middleMessage;
                    }
                    $(".table-order-info").append(
                        "<tr class='add'>"+
                        "<td>"+(data.order[i].isQuick?"加急件":"")+"</td>" +
                        "<td>"+data.order[i].orderNo+"</td>"+
                        "<td>"+data.order[i].toName+ "</td>"+
                        "<td>"+data.order[i].cellphone+"</td>"+
                        "<td>"+(data.order[i].city
                        +data.order[i].area
                        +data.order[i].street
                        +data.order[i].address)+"</td>"+
                        // "<td>"+(data.order[i].user==null?"":data.order[i].user.stationName+"</br>"+formatTime(data.order[i].createDate))+"</td>"+
                        // "<td>"+(data.order[i].middleUser==null?"":data.order[i].middleUser.stationName+"</br>"+formatTime(data.order[i].middleDate))+"</td>"+
                        // "<td>"+(data.order[i].pack==null?"":data.order[i].pack.packageUserName+"</br>"+formatTime(data.order[i].pack.createTime ))+"</td>"+
                        // "<td>"+(data.order[i].receiveUser==null?"":data.order[i].receiveUser.stationName+"</br>"+formatTime(data.order[i].receiveDate))+"</td>"+
                        // "<td>"+(data.order[i].deliverUser==null?"":data.order[i].deliverUser.stationName+"</br>"+formatTime(data.order[i].deliverDate))+"</td>"+
                        "<td>"+msg+"</td>"+
                        "</tr>"
                    );
                }
                //清空操作
                $("input[name='inquire_chose']:checked").each(function () {
                    if(this.checked==true){
                        $(this).prop('checked', false);
                    }
                });
                $("#inquire_number").val("");
                $("#inquire_receiver").val("");
                $("#inquire_tel").val("");
            }
        });
    });
    //清除按钮功能
    $(".inquire-clean").click(function() {
        $("input[name='inquire_chose']:checked").each(function () {
            if(this.checked==true){
                $(this).prop('checked', false);
            }
        });
        $(".inquire-number").val("");
        $(".inquire-receiver").val("");
        $(".inquire-tel").val("");
    });
});